package net.lee.shiro.demo.config;

import com.alibaba.druid.filter.Filter;
import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;
import com.alibaba.druid.wall.WallConfig;
import com.alibaba.druid.wall.WallFilter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.sql.DataSource;
import java.util.List;

/**
 * Create by lishijun on 2018/4/10
 * Company: lianzhong
 * Domain:  ourgame.com
 * Department:Web Developer
 */
@Configuration

public class UserSystemDataSourceConfig {

    @Bean
    @Primary
    public DataSource userSystemDataSource(WallFilter wallFilter)
    {
        DruidDataSource druidDataSource = DruidDataSourceBuilder.create().build();
        List<Filter> proxyFilter = druidDataSource.getProxyFilters();
        proxyFilter.add(wallFilter);
        druidDataSource.setProxyFilters(proxyFilter);
        return druidDataSource;
    }

    @Bean
    public WallFilter wallFilter(WallConfig wallConfig) {
        WallFilter wallFilter = new WallFilter();
        wallFilter.setConfig(wallConfig);
        return wallFilter;
    }

    @Bean
    public WallConfig wallConfig() {
        WallConfig wc = new WallConfig();
        wc.setMultiStatementAllow(true);
        wc.setNoneBaseStatementAllow(true);
        return wc;
    }


}
